﻿#define _CRT_SECURE_NO_WARNINGS 1
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <string.h>
#include <math.h>
#include <unordered_map>
using namespace std;
struct ListNode {
     int val;
     ListNode *next;
     ListNode() : val(0), next(nullptr) {}
     ListNode(int x) : val(x), next(nullptr) {}
     ListNode(int x, ListNode *next) : val(x), next(next) {}
};

class Solution {
public:
    ListNode* addTwoNumbers(ListNode* l1, ListNode* l2) {
        int add = 0, sum = 0;
        ListNode* head = new ListNode();
        ListNode* tmp = head;
        while (l1 != nullptr && l2 != nullptr)
        {
            sum = l1->val + l2->val + add;
            l1 = l1->next;
            l2 = l2->next;
            ListNode* Node = new ListNode();
            Node->val = sum % 10;
            add = sum / 10;
            tmp->next = Node;
            tmp = tmp->next;
        }
        while (l1)
        {
            sum = l1->val + add;
            l1 = l1->next;
            ListNode* Node = new ListNode();
            Node->val = sum % 10;
            add = sum / 10;
            tmp->next = Node;
            tmp = tmp->next;
        }
        while (l2)
        {
            sum = l2->val + add;
            l2 = l2->next;
            ListNode* Node = new ListNode();
            Node->val = sum % 10;
            add = sum / 10;
            tmp->next = Node;
            tmp = tmp->next;
        }
        while (add)
        {
            sum = add;
            ListNode* Node = new ListNode();
            Node->val = sum % 10;
            add = sum / 10;
            tmp->next = Node;
            tmp = tmp->next;
        }
        return head->next;
    }
};

int main()
{
    return 0;
}